/////////////////////////////////////////////////////////////////////////////
//
//  Fifteen Puzzle
//  Kolonitsky Developers Alliance (c) 2012
//  All rights received
//
/////////////////////////////////////////////////////////////////////////////

package view.skins
{

    import caurina.transitions.Tweener;

    import flash.display.Bitmap;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFieldType;
    import flash.text.TextFormat;

    import org.kolonitsky.alexey.ui.SimpleButton;

    import view.events.GameEvent;

    public class ResultSkin extends Sprite
    {
        public function ResultSkin()
        {
            imgSteps = new ImageAssets.STEPS_BITMAP();
            addChild(imgSteps);

            imgDuration = new ImageAssets.TIME_BITMAP();
            addChild(imgDuration);

            tfSteps = createTextField();
            addChild(tfSteps);

            tfDuration = createTextField();
            addChild(tfDuration);

            btnBack = new SimpleButton("", new ImageAssets.BTN_MENU_BITMAP());
            btnBack.addEventListener(MouseEvent.CLICK, btnBack_clickHandler);
            addChild(btnBack);

            addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
        }

        private var _duration:Number;

        public function get duration():Number
        {
            return _duration;
        }

        public function set duration(duration:Number):void
        {
            _duration = duration;
            if (tfDuration)
                tfDuration.text = String(duration);
        }

        private var _stepCount:uint;

        public function get stepCount():uint
        {
            return _stepCount;
        }

        public function set stepCount(stepCount:uint):void
        {
            _stepCount = stepCount;
            if (tfSteps)
                tfSteps.text = String(stepCount);
        }




        //-------------------------------------------------------------------
        //
        //  Private
        //
        //-------------------------------------------------------------------

        private var btnBack:SimpleButton;
        private var imgSteps:Bitmap;
        private var imgDuration:Bitmap;
        private var tfSteps:TextField;
        private var tfDuration:TextField;

        private function createTextField():TextField
        {
            var result:TextField = new TextField();
            result.selectable = false;
            result.type = TextFieldType.DYNAMIC;
            result.autoSize = TextFieldAutoSize.LEFT;
            result.multiline = false;
            result.defaultTextFormat = new TextFormat("_sans", "20", 0xFF6600, true);
            result.mouseEnabled = false;
            return result;
        }

        private function addedToStageHandler(event:Event):void
        {
            var sw:Number = stage.stageWidth || stage.width;
            var sh:Number = stage.stageHeight || stage.height;

            imgSteps.x = Config.BOARD_LEFT;
            imgSteps.y = Config.BOARD_TOP;

            imgDuration.x = Config.BOARD_LEFT;
            imgDuration.y = Config.BOARD_TOP + 100;

            tfSteps.x = Config.BOARD_LEFT + 100;
            tfSteps.y = imgSteps.y + 20;

            tfDuration.x = Config.BOARD_LEFT + 100;
            tfDuration.y = imgDuration.y + 20;

            btnBack.x = 20;
            btnBack.y = 20;
        }

        private function btnBack_clickHandler(event:MouseEvent):void
        {
            dispatchEvent(new GameEvent(GameEvent.MENU, true, false));
        }


    }
}
